package com;

import java.io.FileWriter;
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;
import java.net.URL;

/**
 * Created by IntelliJ IDEA.
 * User: BGONZ8
 * Date: 9/24/11
 * Time: 11:50 AM
 * To change this template use File | Settings | File Templates.
 */
public class RestPostTestCase extends AbstractTestCase
{

    public RestPostTestCase() throws Exception
    {
        super();
    }

    public RestPostTestCase(String endpoint, String requestParameters)  throws Exception
    {
        super();
        this.endpoint = endpoint;
        this.requestParameters = requestParameters;
    }

    public String getResult() {

        String retval = "";
        retval = retval + "\n\n ============================= REST POST TEST CASE  ========================================\n\n";
        retval = retval + "\n\n" + "Comment:\n" + this.getUserComment() + "\n\n" ;
        retval = retval + "End Point:\n" ;
        retval = retval + this.getEndpoint() + "\n\n";
        retval = retval + "Reply Data:\n" ;
        retval = retval +  reply + "\n\n";
        retval = retval + "Post Data:\n" ;
        retval = retval + this.getTxFile().getXmlString() + "\n";
        return retval;
    }
    public void submit() throws Exception
    {
        try
        {
            String xml_data = getPostData();
            URL formAction = new URL(endpoint);
            FileWriter fw = new FileWriter("C:\\packages\\BNX\\Data\\transactionHistory\\postResult.txt");
            util.postData(new StringReader(xml_data), formAction, fw);

            reply = reply + "See file for details at C:\\packages\\BNX\\Data\\transactionHistory\\postResult.txt \n\n\n";
        }
        catch(Exception e)
        {
            reply = reply + "ERROR: " + e.getMessage() + "\n\n";
        }
    }



}
